const query = {
  type: '2',
  page: '1',
  limit: '3'
}

const myLike = async () => {
  console.log(111)
  const { data: { data } } = await axios.get('/user/userDataList', { params: query })
  const { list: { count, totalPages, pageSize, currentPage } } = data

  const htmlStr = data.list.data.map(ele => {
    const { catename, id, title, author, keywords, lovenum, pic, tags, click, description, ishot, istop, create_date } = ele
    let picSrc
    if (pic) {
      picSrc = `http://124.223.14.236:8060/${pic}`
    }
    else {
      picSrc = `./static/images/default.png`
    }
    return `
                <li>
                  <a href="javascript:;">
                    <span class="thumbnail">
                      <img class="thumb" src="${picSrc}" />
                    </span>
                    <span class="text">${title}</span>
                    <span class="text-muted post-views">已点赞(${lovenum||0})</span>
                    <button class="btn btn-xs btn-danger" data-id="${id}"><i class="fa fa-trash"></i>&nbsp;取消点赞</button>
                  </a>
                </li>
    `
  }).join('')
  $('.items-01').html(htmlStr || '暂无文章数据。。。')

  if (!count) {
    $('#page-box').hide()
  }
  renderPage(count)

}
myLike()

$('.items-01').on('click', 'button', async function () {
  const id = $(this).attr('data-id')
  const res = await axios.get('/user/userDataHandle', {
    params: {
      type: 2,
      article_id: id,
      action: 'del',
    }
  })
  layer.msg('取消点赞成功', {
    icon: 1,
    offset: '20px'
  })

  myLike()
})


const laypage = layui.laypage
function renderPage(count) {
  laypage.render({
    elem: 'page-box'
    , count: count
    , theme: '#FF5722'
    , limit: '3'
    , curr: query.page
    , last: '尾页'
    , layout: ['page', 'next', 'count']
    , jump: function (obj, first) {
      //obj包含了当前分页的所有参数，比如：
      // console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
      // console.log(obj.limit); //得到每页显示的条数
      query.page = obj.curr
      query.limit = obj.limit
      //首次不执行
      if (!first) {
        myLike()
      }
    }
  })
}
